package com.nus.servlets;

import com.nus.beans.Project;
import com.nus.beans.User;
import com.nus.database.ProjectsDBManager;
import com.nus.database.UserInfoDBManager;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;

/**
 * Created by IntelliJ IDEA.
 * User: dell
 * Date: 11/4/12
 * Time: 11:00 AM
 * To change this template use File | Settings | File Templates.
 */
public class DeleteUserEvaluationsServlet extends AbstractServlet{
    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        String userEvaluationId = request.getParameter("userEvaluation");

        Connection connection = getUserDatabaseConnection(request);
        UserInfoDBManager userInfoDBManager = new UserInfoDBManager(connection);
        userInfoDBManager.deleteUserEvaluation(Integer.parseInt(userEvaluationId));
        userInfoDBManager.close();

        User user = (User) request.getSession().getAttribute("targetUser");

        request.setAttribute("targetUserId", user.getUserId());
        RequestDispatcher dispatcher = request.getRequestDispatcher("viewUserEvaluations.do");
        dispatcher.forward(request, response);
    }
}
